<template>
    
    
</template>


<script setup lang="ts">
  import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
  import { unReadmessageCountApi } from "@/api/Message";
  import { useGlobalStore } from "./stores";
  import { pages }  from './pages.json'

  import { locationApi } from "@/api/Login"

  onLaunch(async () => {

    const f = sessionStorage.getItem("iptoaddress")
    if(!f) {
      locationApi()
      sessionStorage.setItem("iptoaddress", "1")
    }


    const apis = ['navigateTo', 'redirectTo']
    const globalStore = useGlobalStore()
    await globalStore.init()

    apis.forEach(api => {
      uni.addInterceptor(api, {
        invoke(args) {console.log(args)
          
          const path = args.url.substring(1)

          console.log(path)

          const page = pages.find(page => page.path == path)

          

          if(page) {
            if(!globalStore.loginStatus) {console.log("---------------")
              //args.url = "/pages/login?redirect=" + encodeURIComponent(args.url)
              globalStore.login()
            //location.href = "/clientApi/auth/auth"
            return false
              // uni.navigateTo({
              //   url : "/pages/login"
              // })
            }
          }

          return true
        },
        success(args) {
          console.log(args)
        }
        
      })
    })
    console.log("App Launch");
  });
  onShow(() => {
    const globalStore = useGlobalStore()
    if(globalStore.loginStatus) {
      unReadmessageCountApi().then(r => {
        globalStore.unreadMsgCount = r.data
      })

    }
    
  });
  onHide(() => {
    console.log("App Hide");
  });
</script>
<style lang="scss">
  *{
    box-sizing: border-box;
  }
  html,body {
    font-size: 28rpx;
    color: $base-font-color;
  }

  .p-l-r{
    padding-left: $base-space;
    padding-right: $base-space;
  }


  .m-l-10{
margin-left: 10rpx;
}
.m-l-20{
margin-left: 20rpx;
}
.m-l-30{
margin-left: 30rpx;
}
.m-l-40{
margin-left: 40rpx;
}

.m-t-5{
  margin-top: 5rpx;
  }
.m-t-8{
margin-top: 8rpx;
}

.m-t-10{
margin-top: 10rpx;
}
.m-t-20{
margin-top: 20rpx;
}
.m-t-30{
margin-top: 30rpx;
}
.m-t-40{
margin-top: 40rpx;
}
.m-t-60{
margin-top: 60rpx;
}

.PAGE_TITLE{
  font-size: 40rpx;
  color: #000;
}

</style>

